<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Organization extends AppModel{
    public $validate = array(
        'name' => array(
            'rule' => 'notEmpty'
        )

    );
    
    public $hasMany = array(
        'Project' => array(
            'className'  => 'Project',
            'foreignKey' => 'organization_id',
            'order'      => 'Project.created DESC'
        ),
        'Team' => array(
            'className'  => 'Team',
            'foreignKey' => 'organization_id',
            'order'      => 'Team.created DESC'
        ),
        'OrgMember' => array(
            'className'  => 'OrgMember',
            'foreignKey' => 'organization_id',
            'order'      => 'OrgMember.user_id DESC'
        )
    );
    
    public function isOwnedBy($orgId, $user) {
        return $this->field('id', array('id' => $orgId, 'creator_id' => $user)) === $orgId;
    }

    
}

?>
